
function title(e) {
  return {
    content: e.name,
    color: "#ffffff",
    padding: "10",
    fontSize: "10",
    borderRadius: "10",
    borderWidth: "2",
    borderColor: "#00ff00",
    textAlign: "center",
    bgColor: "#000000",
    display: 'ALWAYS',
  }
}

function addressWorking(item) {
  return {
    longitude: item.longitude,
    latitude: item.latitude,
    iconPath: item.icon,
    width: 37,
    height: 37,
    id: item.id,
    zIndex: 1,
    callout: title(item)
  }
}
Page({
  data: {
    shopListNameHide: false,
    markertapHide: false,
    lat: '',
    lon: '',
    markertapShop: '',
    list:[],
    markers: []
  },
  onLoad(options) {
    this.mapCtx = wx.createMapContext('myMap')
    wx.getLocation({
      success: (result) => {
        console.log(result);
        this.setData({
          lat: result.latitude,
          lon: result.longitude
        })
      },
    })
    let list = wx.getStorageSync('info').map.filter(item=>{
      return item.category_id = options.id
    })[0].position
    console.log(list)
    this.setData({
      list:list,
      markers:list.map(addressWorking)
    })
  },
  shopListNameShow() {
    if (this.data.shopListNameHide) {
      this.setData({
        markertapHide: false,
        shopListNameHide: false
      })
    } else {
      this.setData({
        markertapHide: false,
        shopListNameHide: true
      })
    }
  },
  loopShop(e) {
    let that = this
    let shopList = this.data.list
    for (let index = 0; index < shopList.length; index++) {
      if (shopList[index].id === e) {
        console.log(shopList[index]);
        that.setData({
          markertapShop: shopList[index],
          markertapHide: true,
          ["markers[" + index + "].zIndex"]: 2
        })
      } else {
        that.setData({
          ["markers[" + index + "].zIndex"]: 1
        })
      }
    }
  },
  shopListName(e) {
    console.log(e.target.dataset.id);
    this.loopShop(e.target.dataset.id)
    this.setData({
      shopListNameHide: false
    })
  },
  markertap(e) {
    console.log(e);
    console.log(e.markerId);
    this.setData({
      shopListNameHide: false
    })
    this.loopShop(e.markerId)
  },
  getLocation() {
    let _this = this
    wx.getLocation({
      type: 'wgs84',
      success: (result) => {
        console.log(_this.data.markertapShop.shopY);
        wx.openLocation({ //​使用微信内置地图查看位置。
          latitude: parseFloat(_this.data.markertapShop.shopY), //要去的纬度-地址
          // longitude: _this.data.chooseLon, //要去的经度-地址
          longitude: parseFloat(_this.data.markertapShop.shopX), //要去的经度-地址
          name: _this.data.markertapShop.shopName,
          address: _this.data.markertapShop.address
        })
      },
    })

  },
  markertapHide() {
    this.setData({
      markertapHide: false
    })
  },
  // onShareAppMessage(){
  //   let share = getApp().globalData.share
  //   return share
  // }
})